package com.jzg.jcptadmin.data;


import android.text.TextUtils;

import com.jzg.jcptadmin.Utils.MD5Utils;
import com.jzg.jcptadmin.app.AppContext;
import com.jzg.jcptadmin.base.BaseObject;
import com.jzg.jcptadmin.data.vo.AddTaskResultData;
import com.jzg.jcptadmin.data.vo.AdmixedData;
import com.jzg.jcptadmin.data.vo.AppraisersData;
import com.jzg.jcptadmin.data.vo.Canpei;
import com.jzg.jcptadmin.data.vo.CarConfigModel;
import com.jzg.jcptadmin.data.vo.CarDetails;
import com.jzg.jcptadmin.data.vo.CarManagerData;
import com.jzg.jcptadmin.data.vo.CarTypeModel;
import com.jzg.jcptadmin.data.vo.CarTypeSelectModel;
import com.jzg.jcptadmin.data.vo.CheckPriceBean;
import com.jzg.jcptadmin.data.vo.CheckVinBean;
import com.jzg.jcptadmin.data.vo.ChooseResultData;
import com.jzg.jcptadmin.data.vo.CityItem;
import com.jzg.jcptadmin.data.vo.CityList;
import com.jzg.jcptadmin.data.vo.EvaluateResultBean;
import com.jzg.jcptadmin.data.vo.FastOnlineData;
import com.jzg.jcptadmin.data.vo.HistoryList;
import com.jzg.jcptadmin.data.vo.MakeList;
import com.jzg.jcptadmin.data.vo.ModelList;
import com.jzg.jcptadmin.data.vo.OfflineDetectionData;
import com.jzg.jcptadmin.data.vo.OrderStatisticsData;
import com.jzg.jcptadmin.data.vo.PlateTypeModel;
import com.jzg.jcptadmin.data.vo.ProvinceList;
import com.jzg.jcptadmin.data.vo.RepairBean;
import com.jzg.jcptadmin.data.vo.ReplyInfo;
import com.jzg.jcptadmin.data.vo.SourceData;
import com.jzg.jcptadmin.data.vo.StatusData;
import com.jzg.jcptadmin.data.vo.StyleList;
import com.jzg.jcptadmin.data.vo.SuccessData;
import com.jzg.jcptadmin.data.vo.SuccessValuationData;
import com.jzg.jcptadmin.data.vo.TaskViewData;
import com.jzg.jcptadmin.data.vo.TotalCountInfo;
import com.jzg.jcptadmin.data.vo.TouXiangInfo;
import com.jzg.jcptadmin.data.vo.UpLoadCarData;
import com.jzg.jcptadmin.data.vo.UpLoadImageData;
import com.jzg.jcptadmin.data.vo.UploadVideoData;
import com.jzg.jcptadmin.data.vo.User;
import com.jzg.jcptadmin.data.vo.ValuationDetailData;
import com.jzg.jcptadmin.data.vo.VehicleCheckData;
import com.jzg.jcptadmin.data.vo.VinDetails;
import com.jzg.jcptadmin.data.vo.WorkInfo;
import com.orhanobut.logger.Logger;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.RequestBody;

import java.io.File;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import rx.Observable;

/**
 * Created by jzg on 2015/12/22.
 * 数据层管理类 主要对网络数据，db数据，文件数据，内存数据进行操作
 */

public class DataManager {

    private static DataManager dataManager = new DataManager();

    private DataManager() {

    }

    public static synchronized DataManager getInstance() {
        return dataManager;
    }

    /**
     * 登陆
     *
     * @param params
     * @return
     */
    public Observable<User> login(Map<String, String> params) {
        return AppContext.httpService.login(params);

    }

    /**
     * 修改昵称
     *
     * @param params
     * @return
     */
    public Observable<BaseObject> updateNickName(Map<String, String> params) {
        return AppContext.httpService.updateNickname(params);

    }

    /**
     * 修改头像
     *
     * @return
     */
    public Observable<TouXiangInfo> updateImage(String userid, String path) {
        File imgFile = new File(path);
        Map<String, String> params = new HashMap<String, String>();
        params.put("userid", userid);
        params.put("op", "editHeadPic");
        params.put("tokenid", "6");
        Map<String, Object> signMap = new HashMap<>();
        signMap.putAll(params);
        RequestBody fileBody = RequestBody.create(MediaType.parse("image/png"), imgFile);
        RequestBody userId = RequestBody.create(MediaType.parse("text/plain"), userid);
        RequestBody p = RequestBody.create(MediaType.parse("text/plain"), "editHeadPic");
        RequestBody sign = RequestBody.create(MediaType.parse("text/plain"), MD5Utils.getMD5Sign(signMap));
        Map<String, RequestBody> params1 = new HashMap<String, RequestBody>();
        params1.put("image\"; filename=\"" + imgFile.getName() + "", fileBody);
        params1.put("userId", userId);
        params1.put("op", p);
        params1.put("sign", sign);
        return AppContext.httpService.updateImage(params1);

    }

    public static void setValue(Map map, Object thisObj) {
        Set set = map.keySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            Object obj = iterator.next();
            Object val = map.get(obj);
            setMethod(obj, val, thisObj);
        }
    }

    public static void setMethod(Object method, Object value, Object thisObj) {
        Class c;
        try {
            c = Class.forName(thisObj.getClass().getName());
            String met = (String) method;
            met = met.trim();
            if (!met.substring(0, 1).equals(met.substring(0, 1).toUpperCase())) {
                met = met.substring(0, 1).toUpperCase() + met.substring(1);
            }
            if (!String.valueOf(method).startsWith("set")) {
                met = "set" + met;
            }
            Class types[] = new Class[1];
            types[0] = Class.forName("java.lang.String");
            Method m = c.getMethod(met, types);
            m.invoke(thisObj, value);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }

    /**
     * 加载vin搜索数据
     * 快速线上评估接口
     * @return
     */
    public Observable<FastOnlineData> loadOnLineEvaluationData(Map<String, String> params) {

        return AppContext.httpService.loadOnLineEvaluationData(params);
    }

    /**
     * 加载vin搜索数据
     *  线下评估接口
     * @return
     */
    public Observable<OfflineDetectionData> loadOffLineEvaluationData(int pageIndex,String ...p) {

        Map<String, String> params = new HashMap<String, String>();
        params.put("op", "GetOffLineList");
        params.put("pageIndex", String.valueOf(pageIndex<1?1:pageIndex));
        params.put("userid", p[0]);
        params.put("datetype", p[1]);
        params.put("status", p[2]);
        params.put("Operation", p[3]);
        params.put("tokenid", "6");
        if (!p[4].equals("")) {
            params.put("PageId", p[4]);
        }
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        Logger.e("专业线下列表" + params.toString());
        return AppContext.httpService.loadOfflineDetectionNew(params);

    }

    /**
     * 加载品牌列表
     *
     * @param params
     * @return
     */
    public Observable<MakeList> loadBrand(Map<String, String> params) {
        return AppContext.globalHttpService.loadBrand(params);
    }

    /**
     * 加载车系列表
     *
     * @param params
     */
    public Observable<ModelList> loadModel(Map<String, String> params) {
        return AppContext.globalHttpService.loadModel(params);
    }


    /**
     * 加载车型列表
     *
     * @param params 车系请求参数
     * @return
     */
    public Observable<StyleList> loadStyle(Map<String, String> params) {
        return AppContext.globalHttpService.loadStyle(params);
    }

    /**
     * 加载省列表
     *
     * @param params
     * @return
     */
    public Observable<ProvinceList> loadProvince(Map<String, String> params) {
        return AppContext.cityHttpService.loadProvince(params);
    }

    /**
     * 加载市列表
     *
     * @param params
     * @return
     */
    public Observable<CityList> loadCity(Map<String, String> params) {
        return AppContext.cityHttpService.loadCity(params);
    }

    public Observable<FastOnlineData> loadFastOnlineData(String userID, String datetype,
                                                         String status, String Operation, String PageId, String isShowAll, String vin) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("userid", userID);
        params.put("datetype", datetype);
        params.put("status", status);
        params.put("Operation", Operation);
        params.put("vin", vin);
        params.put("isShowAll", isShowAll);//0只显示线上，1显示线上线下
        params.put("tokenid", "6");
        if (!PageId.equals("")) {
            params.put("PageId", PageId);
        }
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        Logger.e(params.toString());
        return AppContext.httpService.loadFastOnlineData(params);
    }

    public Observable<CarDetails> loadFastOnlineDetailData(String userID, String taskId) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("userid", userID);
        params.put("taskId", taskId);
        params.put("type", "details");
        params.put("tokenid", "6");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        Logger.e("快速线上" + params.toString());
        return AppContext.httpService.loadFastOnlineDeatilData(params);
    }

    public Observable<OfflineDetectionData> loadOfflineDetectionData(String userID, String datetype, String status, String Operation, String PageId) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("op", "GetOffLineList");
        params.put("userid", userID);
        params.put("datetype", datetype);
        params.put("status", status);
        params.put("Operation", Operation);
        params.put("tokenid", "6");
        if (!PageId.equals("")) {
            params.put("PageId", PageId);
        }
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        Logger.e("专业线下列表" + params.toString());
        return AppContext.httpService.loadOfflineDetectionData(params);

    }

    /**
     * 加载估值结果信息
     *
     * @param params
     * @return
     */
    public Observable<ValuationDetailData> loadValuationDetail(Map<String, String> params) {

//        Map<String, Object> map = new HashMap<String, Object>();
//        map.put("ModelId", modelId);
//        String sign = MD5Utils.getMD5Sign(map);

//        params.put("sign", sign);
        params.put("tokenid", "6");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.loadValuationDetail(params);
    }

    /**
     * 加载车源机构
     *
     * @return
     */
    public Observable<SourceData> loadSourceData(String string, String userId) {
        //op=GetSource
        Map<String, String> params = new HashMap<String, String>();
        params.put("op", string);
        params.put("tokenid", "6");
        params.put("userId", userId);
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.loadSourceData(params);
    }

    /**
     * 提交
     *
     * @return
     */
    public Observable<SuccessData> CommitData(Map<String, String> params) {
        params.put("tokenid", "6");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.CommitData(params);
    }

    /**
     * 加载状态
     *
     * @return
     */
    public Observable<StatusData> loadStatus(Map<String, String> params) {
        //TODO
//        Map<String, String> params = new HashMap<String, String>();
//        params.put("tokenid","6");
//        Map<String,Object> maps = new HashMap<>();
//        maps.putAll(params);
//        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.StatusData(params);
    }

    /**
     * 加载列表详情
     *
     * @return
     */
    public Observable<TaskViewData> loadTaskView(String id, String userid) {
        //op=GetSource
        Map<String, String> params = new HashMap<String, String>();
        params.put("op", "GetDetail");
        params.put("taskid", id);
        params.put("userid", userid);
        // params.put("userid",userid);
        params.put("tokenid", "6");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        Logger.e("线下任务参数" + params.toString());
        return AppContext.httpService.TaskViewData(params);
    }

    public Observable<ReplyInfo> UploadReplay(String userId, String carId, String des) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("userId", userId);
        params.put("carId", carId);
        params.put("des", des);
        params.put("tokenid", "6");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.postReplay(params);
    }

    /**
     * 专业线下检测删除数据
     *
     * @return
     */
    public Observable<SuccessData> ZyOperationData(String userId, String type, String Taskid, String AppraiseBackReason, String Status) {
        //op=GetSource
        Map<String, String> params = new HashMap<String, String>();
        params.put("op", type);
        params.put("taskid", Taskid);
        params.put("tokenid", "6");
        params.put("userId", userId);
        if (!TextUtils.isEmpty(AppraiseBackReason)) {
            params.put("AppraiseBackReason", AppraiseBackReason);
        }
        if (!TextUtils.isEmpty(Status)) {
            params.put("Status", Status);
        }
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.DeleteData(params);
    }


    /**
     * 上传图片
     *
     * @return
     */
    public Observable<UpLoadImageData> UploadImage(String path, String itemid,String carid) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("tokenid","6");
        map.put("itemid",itemid);
        map.put("carid",carid);
        Map<String,Object> maps = new HashMap<>();
        maps.putAll(map);


        File imgFile = new File(path);
        RequestBody fileBody = RequestBody.create(MediaType.parse("image/png"), imgFile);

        RequestBody tokenid = RequestBody.create(MediaType.parse("text/plain"), "6");
        RequestBody itemId = RequestBody.create(MediaType.parse("text/plain"), itemid);
        RequestBody sign = RequestBody.create(MediaType.parse("text/plain"), MD5Utils.getMD5Sign(maps));
        RequestBody carId = RequestBody.create(MediaType.parse("text/plain"), carid);
//        RequestBody.create(MediaType.parse("text/plain"), "");
        Map<String, RequestBody> params = new HashMap<String, RequestBody>();
        params.put("image\"; filename=\"" + imgFile.getName() + "", fileBody);
        params.put("itemid", itemId);
        params.put("tokenid", tokenid);
        params.put("sign", sign);
        params.put("carId", carId);

        //TODO
        return AppContext.httpService.UpLoadImage(params);
    }

    /**
     * 提交车辆数据
     *
     * @return
     */
    public Observable<UpLoadCarData> UploadCarData(Map<String, String> map) {
        map.put("tokenid", "6");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(map);
        map.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.UpLoadCarData(map);
    }

    /**
     * 获取首页消息数据
     *
     * @return
     */
    public Observable<TotalCountInfo> loadTotalCount(Map<String, String> params) {
        return AppContext.httpService.loadTotalCount(params);
    }

    /**
     * 获取首页消息数据
     *
     * @return
     */
    public Observable<WorkInfo> loadWokeInfo(Map<String, String> params) {
        return AppContext.httpService.loadWokeInfo(params);
    }

    /**
     * 加载车辆列表
     *
     * @return
     */
    public Observable<CarManagerData> loadCarListData(String UserID, String PageID, String operation, String ProvinceId, String CityId, String MakeId, String ModelId, String StyleId, String status, String price) {
        Map<String, String> map = new HashMap<>();
        map.put("userId", UserID);
        map.put("pageId", PageID);
        map.put("operation", operation);
        map.put("ProvinceId", ProvinceId);
        map.put("CityId", CityId);
        map.put("MakeId", MakeId);
        map.put("ModelId", ModelId);
        map.put("StyleId", StyleId);
        map.put("status", status);
        map.put("price", price);
        map.put("tokenid", "6");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(map);
        map.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.loadCarListData(map);
    }


    /**
     * 加载vin查询结果
     *
     * @param params
     * @return
     */
    public Observable<VinDetails> loadVinResult(Map<String, String> params) {
        params.put("tokenid", "6");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.loadVinResult(params);
    }

    /**
     * 加载评估历史
     *
     * @param params
     * @return
     */
    public Observable<HistoryList> loadHistory(Map<String, String> params) {
        params.put("tokenid", "6");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.loadHistory(params);
    }


    /**
     * 车辆查看详情
     *
     * @param
     * @return
     */
    public Observable<VehicleCheckData> loadCarData(String userid, String itemid) {
        Map<String, String> params = new HashMap<>();
        params.put("userId", userid);
        params.put("Id", itemid);
        params.put("tokenid", "6");
        // 在这里设置需要post的参数
        Map<String, String> map = new HashMap<String, String>();
        Map<String, Object> maps = new HashMap<String, Object>();
        map.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.loadCarData(params);
    }

    /**
     * 快速线上评估提交数据
     *
     * @param params
     * @return
     */
    public Observable<AddTaskResultData> KsSubmitData(Map<String, String> params) {
        params.put("tokenid", "6");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.KsSubmitData(params);
    }

    /**
     * 修改密码
     *
     * @param
     * @return
     */
    public Observable<SuccessData> changePd(String UserId, String OldPassword, String NewPassword) {

        Map<String, String> params = new HashMap<>();
        params.put("UserId", UserId);
        params.put("OldPassword", OldPassword);
        params.put("NewPassword", NewPassword);
        params.put("tokenid", "6");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.changePd(params);
    }

    /**
     * 快速线上操作
     */
    public Observable<SuccessData> OperationData(String type, String id, String appraiseback, String appraiseprice, String appraisedes, String userid) {

        Map<String, String> params = new HashMap<>();
        params.put("tokenid", "6");
        if (!TextUtils.isEmpty(type)) {
            params.put("type", type);
        }
        if (!TextUtils.isEmpty(id)) {
            params.put("taskid", id);
        }
        if (!TextUtils.isEmpty(appraiseback)) {
            params.put("appraiseback", appraiseback);
        }
        if (!TextUtils.isEmpty(appraiseprice)) {
            params.put("appraiseprice", appraiseprice);
        }
        if (!TextUtils.isEmpty(appraisedes)) {
            params.put("appraisedes", appraisedes);
        }
        if (!TextUtils.isEmpty(userid)) {
            params.put("userId", userid);
        }
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.OperationData(params);

    }

    /**
     * 线上退回  审核驳回
     * @param type
     * @param userId
     * @param B2CPrice    售车价
     * @param C2BPrice  收车价
     * @param appraiseback  原因
     * @return
     */
    public Observable<SuccessData> OperationBack(String type, String userId, String B2CPrice, String C2BPrice,String appraiseback,String  taskid ) {

        Map<String, String> params = new HashMap<>();
        params.put("tokenid", "6");
        if (!TextUtils.isEmpty(type)) {
            params.put("type", type);
        }
        if (!TextUtils.isEmpty(userId)) {
            params.put("userId", userId);
         }
        if (!TextUtils.isEmpty(B2CPrice)) {
            params.put("B2CPrice", B2CPrice);
        }
        if (!TextUtils.isEmpty(C2BPrice)) {
            params.put("C2BPrice", C2BPrice);
        }
        if (!TextUtils.isEmpty(appraiseback)) {
            params.put("appraiseback", appraiseback);
        }
        if (!TextUtils.isEmpty(taskid)) {
            params.put("taskid", taskid);
        }
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
       Logger.e(params.toString());
        return AppContext.httpService.OperationBack(params);
    }
    /**
     * 快速线上操作评估
     */
    public Observable<SuccessData> OperationEvaluationData(Map<String, String> params) {
        return AppContext.httpService.OperationData(params);
    }
    public Observable<SuccessValuationData> OperationEvaluationData1(Map<String, String> params) {
        return AppContext.httpService.OperationData1(params);
    }

    /**
     * 新检测流程2.0评估接口
     * @param params
     * @return
     */
    public Observable<EvaluateResultBean> evaluateData(Map<String, String> params) {
        return AppContext.httpService.evaluateData(params);
    }

    /**
     * 获取参配
     */
    public Observable<Canpei> CanPeiData(Map<String, String> params) {
        return AppContext.httpService.CanPeiData(params);
    }

    /**
     * 快速线上操作评估
     */
    public Observable<CheckVinBean> checkVinAccidentOperation(Map<String, String> params) {
        return AppContext.httpService.checkVinAccident(params);
    }

    /**
     * 价格预警查询
     */
    public Observable<CheckPriceBean> checkPrice(Map<String, String> params) {
        return AppContext.httpService.checkPrice(params);
    }

    /**
     * 维保查询
     */
    public Observable<RepairBean> getRepairLog(Map<String, String> params) {
        return AppContext.httpService.getRepairLog(params);
    }

    /**
     * 查询即时评估结果
     *
     * @param UserId
     * @return
     */
    public Observable<ValuationDetailData> LoadValuationDetailData(String UserId, String Styleid, String carId) {

        Map<String, String> params = new HashMap<>();
        params.put("tokenid", "6");
        params.put("UserId", UserId);
        if (!TextUtils.isEmpty(Styleid)) {
            params.put("styleId", Styleid);
        }
        if (!TextUtils.isEmpty(carId)) {
            params.put("carId", carId);
        }
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.LoadValuationDetailData(params);
    }

    /**
     * 查询即时评估结果
     *
     * @param
     * @return
     */
    public Observable<ValuationDetailData> LoadValuationDetailData(Map<String, String> params) {

//        params.put("tokenid", "6");
//        Map<String, Object> maps = new HashMap<>();
//        maps.putAll(params);
//        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.LoadValuationDetailData(params);
    }

    /**
     * 上传视频
     *
     * @return
     */
    public Observable<UploadVideoData> UploadVideo(String path) {
        //op=GetSource
//        Map<String, String> map = new HashMap<String, String>();
//        map.put("tokenid","6");
//        Map<String,Object> maps = new HashMap<>();
//        maps.putAll(map);
//        map.put("sign", MD5Utils.getMD5Sign(maps));
        File videoFile = new File(path);
        RequestBody fileBody = RequestBody.create(MediaType.parse("application/octet-stream"), videoFile);
        Map<String, RequestBody> params = new HashMap<String, RequestBody>();
        params.put("application\"; filename=\"" + videoFile.getName() + "", fileBody);
       /* Map<String,Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));*/

        //TODO
        return AppContext.httpService.UpLoadVideo(params);
    }

    /**
     * 待上传
     *
     * @param
     * @return
     */
    public Observable<SuccessData> upLoadTaskData(Map<String, RequestBody> params, String path, int type) {
        //text/x-markdown
        File zipFile = new File(path);
        RequestBody fileBody = RequestBody.create(MediaType.parse("application/x-zip-compressed"), zipFile);
        params.put("application\"; filename=\"" + zipFile.getName() + "", fileBody);
        if (type == 0) {
            return AppContext.httpService.upLoadTaskData(params);
        } else {
            return AppContext.httpService.upLoadTaskData1(params);
        }

    }

    /***
     * 快速线上任务被驳回后修改更新
     * @param params
     * @return
     */
    public Observable<SuccessData> uploadQuickTaskData(Map<String,String> params){
        return AppContext.httpService.upLoadQuickTaskData(params);
    }

    //线下任务上传
    public Observable<SuccessData> upLoadOffOnLineTaskData(Map<String, String> params) {//////

        return AppContext.httpService.upLoadOffOnLineData(params);
    }

    /**
     * 线下任务详情
     *
     * @param
     * @return
     */
    public Observable<CarDetails> OffLineTaskViewData(Map<String, String> params) {
        return AppContext.httpService.LoadOffOnLineTaskViewData(params);
    }

    /***
     * 评估师端
     * @param pageIndex 当前页码
     * @param p String userID, String datetype,String status, String Operation, String PageId, String isShowAll, String vin
     * @return
     */
    public Observable<FastOnlineData> loadFastOnlineDataNew(int pageIndex,String... p) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("pageIndex", String.valueOf(pageIndex<1?1:pageIndex));
        params.put("userid", p[0]);
        params.put("datetype", p[1]);
        params.put("status", p[2]);
        params.put("Operation", p[3]);
        if (!p[4].equals("")) {
            params.put("PageId", p[4]);
        }
        params.put("isShowAll", p[5]);//0只显示线上，1显示线上线下
        params.put("vin", p[6]);
        params.put("tokenid", "6");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        Logger.e(params.toString());
        return AppContext.httpService.loadFastOnlineDataNew(params);
    }

    /**
     * 线上根据vin搜索
     * @param params
     * @return
     */
    public Observable<FastOnlineData> loadFastOnlineSearchByVinDataNew( Map<String, String> params) {
        return AppContext.httpService.loadFastOnlineDataNew(params);
    }

    /***
     *  带任务认领的线下任务列表获取接口
     * @param pageIndex 当前页
     * @param p userID, String datetype, String status, String Operation, String PageId
     * @return
     */
    public Observable<OfflineDetectionData> loadOfflineDetectionNew(int pageIndex,String ...p) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("op", "GetOffLineList");
        params.put("pageIndex", String.valueOf(pageIndex<1?1:pageIndex));
        params.put("userid", p[0]);
        params.put("datetype", p[1]);
        params.put("status", p[2]);
        params.put("Operation", p[3]);
        params.put("tokenid", "6");
        if (!p[4].equals("")) {
            params.put("PageId", p[4]);
        }
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        Logger.e("专业线下列表" + params.toString());
        return AppContext.httpService.loadOfflineDetectionNew(params);
    }

    /**
     * 线下根据vin搜索
     * @param params
     * @return
     */
    public Observable<OfflineDetectionData> loadOfflineSearchByVinDetectionNew(Map<String, String> params ) {
        return AppContext.httpService.loadOfflineDetectionNewSearchByVin(params);
    }
    /***
     *
     * 线上任务‘认领’以及线上线下‘审核认领’操作接口<br/>
     * "type", "renling" :快速线上任务认领操作 <br/>
     * "type", "ShenHeRenling" 快速线上和线下任务认领审核操作 <br/>
     * @return
     */

    public Observable<SuccessData> claimTask(Map<String,String> params){
        params.put("tokenid", "6");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return AppContext.httpService.OperationDataNew(params);
    }

    public Observable<CityItem> getCityData(Map<String, String> params) {
        return AppContext.httpService.getCityData(params);
    }
    public Observable<OrderStatisticsData> getOrderData(Map<String, String> params) {
        return AppContext.httpService.getOrderData(params);
    }

    public Observable<AppraisersData> getAppraisersData(Map<String, String> params) {
        return AppContext.httpService.getAppraisersData(params);
    }

    public Observable<AppraisersData> getOrganizationData(Map<String, String> params) {
        return AppContext.httpService.getOrganizationData(params);
    }
    /**
     * 获取首页消息数据
     *
     * @return
     */
    public Observable<ChooseResultData> loadChooseResult(Map<String, String> params) {
        return AppContext.httpService.loadChooseResult(params);
    }

    /**
     * Created by 李波 on 2017/3/17.
     * 获取车辆参配信息
     */
    public Observable<ResponseJson<AdmixedData>> getCarParamConfig(Map<String, String> params) {
        return AppContext.CarParamhttpService.getAdmixedData(params);
    }

    /**
     * Created by 李波 on 2017/3/20.
     * 备选车型 根据车系请求车型列表和差异配置
     */
    public Observable<CarTypeSelectModel> getCarDiff(Map<String, String> params) {
        return AppContext.CarParamhttpService.getCarDiff(params);
    }

    /**
     * 铭牌型号
     */
    public Observable<PlateTypeModel> getPlateTypes(Map<String, String> params) {
        return AppContext.CarParamhttpService.getPlateTypes(params);
    }

    /**
     * 获取品牌车系
     */
    public Observable<CarTypeModel> getCarTypes(Map<String, String> params) {
        return AppContext.CarParamhttpService.getCarTypes(params);
    }

    /**
     * 获取变速箱、驱动方式、排量
     */
    public Observable<List<CarConfigModel.MemberValueBean>> getCarConfig(Map<String, String> params) {
        return AppContext.globalHttpService.getCarConfig(params);//TODO 地址上线前要换
    }
}
